import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;

public class Version {
	
	private String identifier;
	
	private Date releaseDate;
	
	private LinkedList<String> sourceList;
	private LinkedList<MetricClass> metricClasses;
	
	private int releaseSequenceNum;
	
	public Version(String identifier, Date releaseDate)
	{		
		this.identifier = identifier;
		this.releaseDate = releaseDate;
		
		sourceList = new LinkedList<String>();
		metricClasses = new LinkedList<MetricClass>();
	}

	/**
	 * A Version must include the source list, unique version identifier
	 * and release date.
	 * @param sourceList - the source list.
	 * @param identifier - the unique version identifier.
	 * @param releaseDate - the release date of this version.
	 */
	public Version(LinkedList<String> sourceList, String identifier, Date releaseDate)
	{
		this.sourceList = sourceList;
		this.identifier = identifier;
		this.releaseDate = releaseDate;
		
		metricClasses = new LinkedList<MetricClass>();
	}

	/**
	 * @return Returns the identifier.
	 */
	public String getIdentifier() {
		return identifier;
	}

	/**
	 * @param identifier The identifier to set.
	 */
	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}

	/**
	 * @return Returns the metricClasses.
	 */
	public LinkedList<MetricClass> getMetricClasses() {
		return metricClasses;
	}

	/**
	 * @param metricClasses The metricClasses to set.
	 */
	public void setMetricClasses(LinkedList<MetricClass> metricClasses) {
		this.metricClasses = metricClasses;
	}

	/**
	 * @return Returns the releaseDate.
	 */
	public Date getReleaseDate() {
		return releaseDate;
	}

	/**
	 * @param releaseDate The releaseDate to set.
	 */
	public void setReleaseDate(Date releaseDate) {
		this.releaseDate = releaseDate;
	}

	/**
	 * @return Returns the sourceLocation.
	 */
	public LinkedList<String> getSourceList() {
		return sourceList;
	}

	/**
	 * @param sourceLocation The sourceLocation to set.
	 */
	public void setSourceList(LinkedList<String> sourceLocation) {
		this.sourceList = sourceLocation;
	}
	
	/**
	 * @return Returns the releaseSequenceNum.
	 */
	public int getReleaseSequenceNum() {
		return releaseSequenceNum;
	}

	/**
	 * @param releaseSequenceNum The releaseSequenceNum to set.
	 */
	public void setReleaseSequenceNum(int releaseSequenceNum) {
		this.releaseSequenceNum = releaseSequenceNum;
	}
	
	/**
	 * Adds the specified MetricClass to the current version.
	 * @param metricClass - the MetricClass to add.
	 */
	public void addMetricClass(MetricClass metricClass)
	{
		metricClasses.add(metricClass);
	}
	
	public void addSourceFile(String fileName)
	{		
		sourceList.add(fileName);
	}
	
	/**
	 * Removes the specified MetricClass from this current version.
	 * @param metricClass - the MetricClass to remove.
	 */
	public boolean removeMetricClass(MetricClass metricClass)
	{
		return metricClasses.remove(metricClass);
	}
	
	/**
	 * TODO: Replace linear search.
	 * @param className - the name of the metric class to retrieve.
	 * @return - the MetricClass (if it exists).
	 */
	public MetricClass getMetricClass(String className)
	{
		Iterator it = metricClasses.iterator();
		MetricClass currentMetricClass = null;
		while (it.hasNext())
		{
			currentMetricClass = (MetricClass)it.next();
			if (currentMetricClass.getName().equals(className))
				return currentMetricClass;
		}
		return null;
	}
	
}
